﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="OrderTracker.cs" company="">
//   
// </copyright>
// <summary>
//   The order tracker.
// </summary>
// --------------------------------------------------------------------------------------------------------------------


using System;

namespace Systemathics.FrameWork
{
    [Serializable]
    public sealed class OrderTracker : Order
    {
        public bool MustBeCancelledOnNextStatus { get; set; }
        public bool MustBeModifiedOnNextStatus { get; set; }

        #region constructor 

        public OrderTracker(Order order) : base(order.InstrumentId, order.StaticData, order.Style, order.Side, order.TargetPrice, order.TargetQuantity, order.StrategyId)
        {
            Id = order.Id;
            Ext = order.Ext;

            MustBeCancelledOnNextStatus = false;
            MustBeModifiedOnNextStatus = false;
        }

        #endregion constructor

        #region New Order status fields
         
        public void SetisSent(bool s)
        {
            isSent = s;
        }
        public void SetSendTime(DateTime t)
        {
            SendTime = t;
        }
        public void SetisAcknoweldged(bool s)
        {
            isAcknowledged = s;
        }
        public void SetAckTime(DateTime t)
        {
            AckTime = t;
        }
        public void SetisRejected(bool s)
        {
            isRejected = s;
        }
        public void SetRejectTime(DateTime t)
        {
            RejectTime = t;
        }
        public void SetRejectReason(string s)
        {
            RejectReason = s;
        }
        public void SetStatus(OrderStatus s)
        {
            Status = s;
        }
        public void SetExecutedAveragePrice(Decimal p)
        {
            ExecutedAveragePrice = p;
        }
        public void SetTotalExecutedQuantity(int qty)
        {
            TotalExecutedQuantity = qty;
        }
        public void SetRemainingQty(int qty)
        {
            RemainingQuantity = qty;
        }
        public void SetPendingQty(int qty)
        {
            PendingQuantity = qty;
        }
        public void SetPendingPrice(Decimal price)
        {
            PendingPrice = price;
        }

        #endregion New Order status fields

        #region Cancel status fileds

        public void SetisCancelling(bool s)
        {
            isCancelling = s;
        }
        public void SetisCancelled(bool s)
        {
            isCancelled = s;
        }
        public void SetCancelRejectNumber()
        {
            CancelRejectionNumber++;
        }
        public void SetCancelQuantity(int s)
        {
            CancelQuantity = s;
        }
        public void SetCancelTime(DateTime t)
        {
            CancelTime = t;
        }
        public void SetCancelAckTime(DateTime t)
        {
            CancelAckTime = t;
        }

        #endregion

        #region Modify status fileds

        public void SetisModifying(bool s)
        {
            isModifying = s;
        }
        public void SetisModified(bool s)
        {
            isModified = s;
        }
        public void SetModifyRejectNumber()
        {
            ModifyRejectedNumber++;
        }
        public void SetModifyTime(DateTime t)
        {
            ModifyTime = t;
        }
        public void SetModifyAckTime(DateTime t)
        {
            ModifyAckTime = t;
        }

        #endregion Modify status fileds

        public void AddExecution(Execution exec)
        {
            exec.Time = Time.Now;
            LastExecution = exec;
            OrderExecutions.Add(LastExecution);
        }
    }
}